﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CarbonExchange.Logger
{
    public class LogUtility {

        public static string BuildExceptionMessage(Exception x) {
			
			Exception logException=x;
			if(x.InnerException!=null)
				logException=x.InnerException;

            StringBuilder strErrorMsg = new StringBuilder();

            if(System.Web.HttpContext.Current != null)
            {
			    strErrorMsg.Append(string.Concat(Environment.NewLine, "Error in Path :", System.Web.HttpContext.Current.Request.Path));
                // Get the QueryString along with the Virtual Path
                strErrorMsg.Append(string.Concat(Environment.NewLine, "Raw Url :", System.Web.HttpContext.Current.Request.RawUrl));
            }

			// Get the error message
            strErrorMsg.Append(string.Concat(Environment.NewLine, "Message :", logException.Message));

			// Source of the message
            strErrorMsg.Append(string.Concat(Environment.NewLine, "Source :", logException.Source));

			// Stack Trace of the error

            strErrorMsg.Append(string.Concat(Environment.NewLine, "Stack Trace :", logException.StackTrace));

			// Method where the error occurred
            strErrorMsg.Append(string.Concat(Environment.NewLine, "TargetSite :", logException.TargetSite));
			return strErrorMsg.ToString();
        }
    }
}
